package com.bussiness.system.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bussiness.system.core.OssCoreService;
import com.bussiness.system.form.OssEntityAuditForm;
import com.bussiness.system.dto.OssEntityDto;
import com.bussiness.system.query.OssEntityQuery;
import com.bussiness.system.api.OssControllerApi;
import com.bussiness.system.entity.OssEntity;
import com.bussiness.system.face.OssService;
import com.bussiness.system.util.Result;

/**
 * 文件上传
 *
 * @author xlr
 * @email 402701653@qq.com
 * @date 2018-09-04 00:34:01
 */
@RestController
public class OssController implements OssControllerApi {

    @Autowired
    private OssService ossService;

    @Autowired
    private OssCoreService ossCoreService;

    /**
     * 列表
     */
    @Override
    public Result list(@RequestBody OssEntityQuery query) {
       return ossCoreService.queryPage( query );
    }

    /**
     * 信息
     */
    @Override
    public Result info(@PathVariable("id" ) Long id) {
        OssEntity oss = ossService.selectById( id );

        return new Result <OssEntity>().success( oss );
    }

    /**
     * 保存
     */
    @Override
    public Result save(@RequestBody OssEntityAuditForm ossForm) {
        OssEntity entity = ossForm.transfer();
        ossService.insert( entity );

        return new Result <>().success();
    }

    /**
     * 修改
     */
    @Override
    public Result update(@RequestBody OssEntityAuditForm ossForm) {
        OssEntity entity = ossForm.transfer();
        ossService.updateById( entity );

        return new Result <>().success();
    }

    /**
     * 删除
     */
    @Override
    public Result delete(@RequestBody Long[] ids) {
        ossService.deleteBatchIds( Arrays.asList( ids ) );

        return new Result <>().success();
    }

}
